<!DOCTYPE html>
<title>XMLSerializer: Don't emit redundant NS declarations</title>
<script src=../../resources/testharness.js></script>
<script src=../../resources/testharnessreport.js></script>
<div id=log></div>
<script>
test(function() {
    var s = '<foo xmlns="http://www.w3.org/1999/xhtml"></foo>';
    var docFrag = new DOMParser().parseFromString(s, 'text/xml');
    var root = docFrag.removeChild(docFrag.firstChild);
    var child = document.createElementNS('http://www.w3.org/1999/xhtml', 'bar');
    child.appendChild(document.createTextNode(''));
    root.appendChild(child);
    var result1 = new XMLSerializer().serializeToString(root);
    assert_equals(result1, '<foo xmlns="http://www.w3.org/1999/xhtml"><bar></bar></foo>');
}, 'XMLSerializer: Don\'t emit redundant declarations of the default NS.');

test(function() {
    var s = '<foo xmlns="http://www.w3.org/1999/xhtml" xmlns:baz="http://example.org/baz"></foo>';
    var docFrag = new DOMParser().parseFromString(s, 'text/xml');
    var root = docFrag.removeChild(docFrag.firstChild);
    var child = document.createElementNS('http://example.org/baz', 'baz:bar');
    child.appendChild(document.createTextNode(''));
    root.appendChild(child);
    var result1 = new XMLSerializer().serializeToString(root);
    assert_equals(result1, '<foo xmlns="http://www.w3.org/1999/xhtml" xmlns:baz="http://example.org/baz"><baz:bar></baz:bar></foo>');
}, 'XMLSerializer: Don\'t emit redundant declarations of a prefix.');
</script>
